package com.daixin.blog.controller;

import com.daixin.blog.dto.CommentDTO;
import com.daixin.blog.dto.QuestionDTO;
import com.daixin.blog.menu.CommentTypeEnum;
import com.daixin.blog.service.CommentService;
import com.daixin.blog.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

/**
 * Author daixin
 */
@Controller
public class QuestionInformationController {
    @Autowired
    private QuestionService questionService;
    @Autowired
    private CommentService commentService;
    @GetMapping("/questionInformation/{id}")
    public String questionInformation(@PathVariable(name = "id") Long id, Model model){
        QuestionDTO questionDTO =questionService.findById(id);
        List<CommentDTO> comments = commentService.listByTargetid(id, CommentTypeEnum.QUESTION);
        //实现阅读数的增加
        questionService.incView(id);
        model.addAttribute("questionInformation", questionDTO);
        model.addAttribute("comments", comments);
        return "questionInformation";
    }
}
